/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.izu.mytruco.service;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ademar
 */
public class CommunicatorServerClient implements Runnable {
    
    protected Socket socket;
    protected Thread thread;
    protected BufferedReader reader;
    protected BufferedWriter writer;

    public CommunicatorServerClient(Socket socket) throws IOException {
        System.out.println("CRIOU O SC");
        this.socket = socket;
        this.reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        this.writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        this.thread = new Thread(this);
        this.thread.start();
    }

    public void run() {
        while(true) {
            try {
                System.out.println("Esperando client mandar msg");
                System.out.println("Client: " + reader.readLine());
            } catch (IOException ex) {
                Logger.getLogger(CommunicatorServerClient.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}
